/* Javascript Functions */

/* =================== Hint System =========================== */
function hint_show(image_root, msg) {	// usage: 	hint_show('<?=IMAGE_ROOT?>', 'test');
	$(".right_top").before('<div id = "hint" class="float_left"><div class="right_top"></div><div class="right_mid_hint"><div class="right_meat"><div class="hint"><div class="float_right"><a href="javascript:void(0)" onclick="hint_close();" ><img src="'+image_root+'delete3_16x16.png" /></a></div>'+msg+'</div></div></div><div class="right_btm"></div></div>');
}

function hint_close() {
	$("#hint").fadeOut();
}

/* =================== MSG Alert Systems ===================== */

function post_msg(msg, color) {
	if (!color) color = 'grey';
    $(".title").after('<div class="msg '+color+'" id="msg">'+msg+'</div>');
    $(".msg").hide().fadeIn("slow");
    setTimeout('$(".msg").fadeOut("slow", function(){$(this).remove()} )', 4000);
}

function sticky_msg(msg, color) {
	if (!color) color = 'grey';
    $(".title").after('<div class="msg '+color+'" id="msg"><a href="javascript:void(0)" onclick="sticky_msg_close(this)">[X]</a> '+msg+'</div>');
    $(".msg").hide().fadeIn("slow");
}

function sticky_msg_close(item) {
	$(item).parent().fadeOut(function(){$(this).remove()});
}

function custom_msg(msg, id, time) {
	var time = (time == null) ? 4000 : time;
    $("#"+id).html('<div class="msg grey" id="msg">'+msg+'</div>');
    $(".msg").hide().fadeIn("slow");
    setTimeout('$(".msg").fadeOut("slow", function(){$(this).remove()} )', time);
}

/* ===================  Input Manipulations  ===================== */

// input onmouseover effects
function removeText_s(x)
{
	document.getElementById(x).value="";
}

function removeText(x,txt)
{
	if (document.getElementById(x).value==txt)
	document.getElementById(x).value="";
}

function putbackText(x,txt)
{
	if (document.getElementById(x).value=="")
	document.getElementById(x).value=txt;
}

// Check max length of input
function checkinput (maxchars, id) {
	 len = document.getElementById(id).value.length;
	 if(len > maxchars) {
	   alert('Too much data in Self Introduction! Please remove '+(len - maxchars)+' characters');
	   return false; }
	 else
	 {
	   return true; }
}

// Define SelectedIndex
function setSelectedIndex(id, value) {
	var x = document.getElementById(id);
	var length = x.options.length;

	for (var i=0;i<length;i++) 
	{		
		if(x.options[i].value == value)
		{
			x.selectedIndex = i;
		}
	}
}

// input character restrictions
function charCheck(e, type) {	//  usage:  onkeydown="return charCheck(event, 'tel');" 
	var keynum;
	var keychar;
	var numcheck;
	if(window.event) // IE
	  {
	  keynum = e.keyCode;
	  }
	else if(e.which) // Firefox/Opera
	  {
	  keynum = e.which;
	  } 
	keychar = String.fromCharCode(keynum);
	if (type=="tel") numcheck = /[\d\x00-\x1F\x7F\x25-28\x2C\x6D]/;  // Telphone number : digits, '-', controls, arrows, delete  
	if (type=="yr") numcheck = /[\d\x00-\x1F\x7F]/;					  // Year: digits, controls
	return numcheck.test(keychar);
}		

